<%@ page import="org.apache.struts.action.Action"%>
<%@page import="com.mbbmap.util.StringUtils"%>
<%@ page import="java.io.*"%>
<%@ page import="java.net.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.util.Map"%>
<%@ page import="java.util.HashMap"%>
<%@ page import="com.mbbmap.app.manager.*"%>
<%@ page import="com.mbbmap.app.EbppKeys"%>
<%@ page import="com.mbbmap.util.*"%>
<%@ page import="com.mbbmap.security.dao.*"%>
<%@ page import="com.mbbmap.app.dao.*"%>

<html>
<head>
<link rel="stylesheet" href="resource/mbb_sec_global.css" type="text/css" />
<%
String strPwdRegExp = (String) session.getAttribute(Constants.PASSWORD_REG_EXP);
String msg = StringUtils.NullSafe((String) request.getAttribute("msg"));
String msg_id = StringUtils.NullSafe((String) request.getAttribute("msg_id"));

String userid = StringUtils.NullSafe((String) request.getAttribute("userid"));
String pass1 = StringUtils.NullSafe((String) request.getAttribute("pass1"));
String pass2 = StringUtils.NullSafe((String) request.getAttribute("pass2"));

boolean showParam = false;
String msgColor = "red";

if (msg_id.equalsIgnoreCase("MSG001") || msg_id.equalsIgnoreCase("MSG002"))
	showParam = true;

if (msg_id.equalsIgnoreCase("MSG999"))
	msgColor = "green";

ArrayList secGroupAccessList = (ArrayList) session.getAttribute(Constants.LOGON_ACCESS_LIST);
SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);
String sUserName = oSecUserDao.getUserName();
String lastLogonDateTime = (String) session.getAttribute(Constants.LAST_LOGON_DATETIME);

String selected = "sec004";
int iSec001 = 0;
int iSec002 = 0;
int iSec003 = 0;
int iSec004 = 0;
int iSec005 = 0;
int iSec006 = 0;
int iSec007 = 0;
int iSec008 = 0;

for(int i=0;i<secGroupAccessList.size();i++){
	SecAccessDao secaccessDao = (SecAccessDao)secGroupAccessList.get(i);
	String strModuleCode  = secaccessDao.getModuleCode();
	if(strModuleCode.equals("SEC001"))
		iSec001 = 1;
	if(strModuleCode.equals("SEC002"))
		iSec002 = 1;
	if(strModuleCode.equals("SEC003"))
		iSec003 = 1;
	if(strModuleCode.equals("SEC004"))
		iSec004 = 1;
	if(strModuleCode.equals("SEC005"))
		iSec005 = 1;
	if(strModuleCode.equals("SEC006"))
		iSec006 = 1;
	if(strModuleCode.equals("SEC007"))
		iSec007 = 1;
	if(strModuleCode.equals("SEC008"))
		iSec008 = 1;
}
%>


<link href="resource/style.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
	    window.history.forward();
	    function noBack() { window.history.forward(); }
	</script>
<style type="text/css"></style>
</head>
<SCRIPT LANGUAGE="JavaScript1.2">
	function getGrpUsers(){
		strGroupCode = document.GetGrpUsersForm.GrpCode[document.GetGrpUsersForm.GrpCode.selectedIndex].value;
		if(strGroupCode==null || strGroupCode==""){
			alert("Please Select Group !");
			return false;
		}
		document.GetGrpUsersForm.selusergrp.value = strGroupCode;
		document.GetGrpUsersForm.action='<%=response.encodeURL("UpdateUsers.do?dispatch=getUsers")%>';
		document.GetGrpUsersForm.submit();
	}

	function UpdUser(){
		var sym = /[^a-zA-z0-9_]/;
		var letters = /[^a-zA-z ]/; 
		strUName = document.EditUserForm.UserName.value;
		if(strUName==null || strUName==""){
			alert("Please enter User Name");
			return false;
		}
		else if(strUName.match(letters)){
			alert("Your name cannot have numbers or symbols");
			return false;
		}

		document.EditUserForm.action='<%=response.encodeURL("UpdateUsers.do?dispatch=updateUsers")%>';
		document.EditUserForm.submit();
	}
	
	function removeuser(strUserID,userID){
		if(strUserID==null || strUserID==""){
			alert("Please enter User ID");
			return false;
		}
		var msg = "Confirm Delete of "+userID;
		
		if (confirm(msg)){
 		document.GetUserForm.sremuser.value = strUserID;
		document.GetUserForm.action='<%=response.encodeURL("UpdateUsers.do?dispatch=remUsers")%>';
		document.GetUserForm.submit();
		}
	}
	 
	function ShowList(){
		var frm = document.EditUserForm;
		frm.action = "UpdateUsers.do?dispatch=getUsers"; 
		frm.submit();
	}
</SCRIPT>
</head>
<%
	ArrayList arlSecGroupList = new ArrayList();
	arlSecGroupList = (ArrayList) session.getAttribute(Constants.SECURITY_UGROUP);
	ArrayList secGroupUserList = new ArrayList();
	secGroupUserList = (ArrayList) session.getAttribute(Constants.SECURITY_USER_LIST);
	
	SecUserDao secuserdao  = (SecUserDao)secGroupUserList.get(0);

	String strESelectedGroup = "";
	String strSelectedGroup = "";
	String strSelectedGroupName = "";
	String strErrLogonMsg = "";
	
	strESelectedGroup = (String) session.getAttribute(Constants.SELECTED_SEC_UGRP);
	strErrLogonMsg = (String) session.getAttribute(Constants.LOGON_ERR_MSG);
	
	if ((strESelectedGroup == null) || (strESelectedGroup.equals(""))){
		strESelectedGroup = "";
		strSelectedGroup = "";
	}else{
		strSelectedGroup = EncryptionHelper.decrypt(strESelectedGroup,ConfigManager.getInstance().get(EbppKeys.ENCRYPTION_PASSPHRASE));
	}
	String strGroupCode = "";
	String strSelectedModule = "";
	String strModuleCode = "";

%>



<body class="home" onload="noBack();"
	onpageshow="if (event.persisted) noBack();" onunload="">

	<a name="top"></a>

	<!-- Header -->
	<%@ include file="/jsp/common/Header.jsp"%>
	<!-- End Header -->

	<div id="bgWrapper">
		<div id="container">

			<div id="titleBar">
				<ul class="topBar">
					<li class="goBackBt"><a
						href="<%=request.getContextPath()%>/ShowSecurityHome.do?dispatch=init"></a></li>

					<li>
						<h1>Modify User</h1>
					</li>
				</ul>
			</div>

			<div id="fullcontent">

				<!-- Security Navigation -->
				<%@ include file="SecurityNavigation.jsp"%>
				<!-- End SecurityNavigation -->


				<div id="contentRightIn">
				
					<!-- Module Title -->
					<table align="center" width=100% border="0" rules="cols" class="tblDetails">
							<thead>
								<tr>
									<th colspan="4">
										<h4>View/Edit Users</h4>
									</th>
								</tr>
							</thead>
								
							<tr class="even">
								<td colspan="2" align="center" style="text-align:center !important;">
									Security Module - User Edit.
									<p style="font-weight:bold;color: <%=msgColor%> !important;"><%=msg%></p>
								</td>
							</tr>
							
							<%
							System.out.println("SecUserEdit.jsp:strErrLogonMsg"+strErrLogonMsg);
							if(strErrLogonMsg != null)
							{
								if(!strErrLogonMsg.equals(""))
								{
							%>
								<th class="pageTitle" colspan="2"><%=strErrLogonMsg%></th>
							<%
								}
							}
							%>
							<tr class="header">
								<td colspan = "2"></td>
							</tr>
							
					</table>

					<%
					if(strErrLogonMsg != null)
					{
						if(strErrLogonMsg.equals(""))
						{
					%>

					<br />

					<form name="EditUserForm" action="" method="post">
						<input type="hidden" name="<%= Constants.TOKEN_KEY %>" value="<%= session.getAttribute(Action.TRANSACTION_TOKEN_KEY) %>" >
						<input type="hidden" name="selusergrp" value="<%=strESelectedGroup%>"> 
						<input type="hidden" name="sremuser" value="<%=secuserdao.getLogonId()%>">
						<table align="center" class="tbldetails" width=100% border="0" rules="cols">
							<thead class="th1">
								<tr>
									<th colspan="5">
										<div class="sectionTableTitle">
											<h2>
												Edit User :
												<%=strSelectedGroupName%></h2>
										</div>
									</th>
							</thead>
							<tr border="0">
								<td width="15%" class="center_note">User Login ID:</td>
								<td width="30%" class="center_note">
									<input type="text" name="UserID" value="<%=secuserdao.getLogonId()%>" size=20 maxlength="10" disabled></td>
								<td width="15%" class="center_note">User Name:</td>
								<td width="30%" class="center_note">
									<input type="text" name="UserName" value="<%=secuserdao.getUserName()%>" size=20 maxlength="60"></td>
								<td width="10%" class="center_note">&nbsp;</td>
							</tr>
							<tr border="0">
								<td width="15%" class="center_note">Full Name:</td>
								<td width="30%" class="center_note">
									<input type="text" name="FullName" value="<%=secuserdao.getFullName()%>" size=20 maxlength="120"></td>
								<td width="15%" class="center_note">Email:</td>
								<td width="30%" class="center_note">
									<input type="text" name="Email" value="<%=secuserdao.getEmail()%>" size=20 maxlength="120"></td>
								<td width="10%" class="center_note">&nbsp;</td>
							</tr>
							<tr border="0">
								<td width="15%" class="center_note">User Dept:</td>
								<td width="30%" class="center_note">
									<input type="text" name="UserDept" value="<%=secuserdao.getDept()%>" size=20 maxlength="120"></td>
								<td width="15%" class="center_note">User Region:</td>
								<td width="30%" class="center_note">
									<select name="UserRegion">
										<%
										String strSelected = "";
										if (secuserdao.getRegion().equalsIgnoreCase("")){
											strSelected = "selected";
										}
										%>
										<option value="" <%=strSelected%>>-- Please Select --</option>
										<%
										strSelected = "";
										if (secuserdao.getRegion().equalsIgnoreCase("MY")){
											strSelected = "selected";
										}
										%>
										<option value="MY" <%=strSelected%>>Malaysia</option>
										<%
										strSelected = "";
										if (secuserdao.getRegion().equalsIgnoreCase("SG")){
											strSelected = "selected";
										}
										%>
										<option value="SG" <%=strSelected%>>Singapore</option>
										<%
										strSelected = "";
										if (secuserdao.getRegion().equalsIgnoreCase("PH")){
											strSelected = "selected";
										}
										%>
										<option value="PH" <%=strSelected%>>Philippines</option>
										<%
										strSelected = "";
										if (secuserdao.getRegion().equalsIgnoreCase("KH")){
											strSelected = "selected";
										}
										%>
										<option value="KH" <%=strSelected%>>Cambodia</option>
									</select>
								</td>
								<td width="10%" class="center_note">&nbsp;</td>
							</tr>
							<tr border="0">
								<td width="15%" class="center_note">User Role:</td>
								<td width="30%" class="center_note">
									<input type="text" name="RoleCode" value="<%=secuserdao.getGroupCode()%>" size=20 maxlength="120" disabled></td>
								<td width="15%" class="center_note">Enabled:</td>
								<td width="30%" class="center_note">
									<input type="text" name="Enable" value="<%=secuserdao.getEnable()%>" size=20 maxlength="120" disabled></td>
								<td width="10%" class="center_note">&nbsp;</td>
							</tr>
							<tr border="0">
								<td width="15%" class="center_note">Bad Pwd Attempt:</td>
								<td width="30%" class="center_note">
									<input type="text" name="BadPwdAttempt" value="<%=secuserdao.getBadPwdAttempts()%>" size=20 maxlength="120" disabled></td>
								<td width="15%" class="center_note">Currently logged on:</td>
								<td width="30%" class="center_note">
									<input type="text" name="CurrentLogon" value="<%=secuserdao.getCurrentLogon()%>" size=20 maxlength="120" disabled></td>
								<td width="10%" class="center_note">&nbsp;</td>
							</tr>
							<tr border="0">
								<td width="15%" class="center_note">Created by:</td>
								<td width="30%" class="center_note">
									<input type="text" name="CreateBy" value="<%=secuserdao.getCreateBy()%>" size=20 maxlength="120" disabled></td>
								<td width="15%" class="center_note">Dormant:</td> 
								<td width="30%" class="center_note">
									<% if(secuserdao.getDormantDays() == 0) { %>
									<input type="text" name="DormantDays" value="<%=secuserdao.getDormantDays()%> day" size=20 maxlength="120" disabled> 
									<%} else { %>
									<input type="text" name="DormantDays" value="<%=secuserdao.getDormantDays()%> days" size=20 maxlength="120" disabled> 
									<% } %>
								</td>
								<td width="10%" class="center_note">&nbsp;</td>
							</tr>
							<tr border="0">
								<td width="15%" class="center_note">Created date:</td>
								<td width="30%" class="center_note">
									<input type="text" name="CreateDate" value="<%=secuserdao.getCreateDate()%>" size=20 maxlength="120" disabled></td>
								<td width="15%" class="center_note">Last login date:</td>
								<td width="30%" class="center_note">
									<input type="text" name="LastLoginDateTime" value="<%=secuserdao.getLastLoginDateTime()%>" size=20 maxlength="120" disabled></td>
								<td width="10%" class="center_note">&nbsp;</td>
							</tr>
							<tr border="0">
								<td width="15%" class="center_note">Updated by:</td>
								<td width="30%" class="center_note">
									<input type="text" name="UpdatedBy" value="<%=secuserdao.getUpdateBy()%>" size=20 maxlength="120" disabled></td>
								<td width="15%" class="center_note">Last Password Changed:</td>
								<td width="30%" class="center_note">
									<input type="text" name="LastPwdChange" value="<%=secuserdao.getLastPwdChange()%>" size=20 maxlength="120" disabled></td>
								<td width="10%" class="center_note">&nbsp;</td>
							</tr>
							<tr border="0">
								<td width="15%" class="center_note">Last Updated date:</td>
								<td width="30%" class="center_note">
									<input type="text" name="LastUpdatedDate" value="<%=secuserdao.getLastUpdateDate()%>" size=20 maxlength="120" disabled></td>
							</tr>
							<tr border="0">
								<td width="15%" class="center_note">&nbsp;</td>
								<td width="30%" class="center_note">&nbsp;</td>
								<td width="15%" class="center_note">&nbsp;</td>
								<td width="10%" class="center_note">
									<input style="width:75px" type="button" name="Back" value="Back" onClick="JavaScript:ShowList();">
								</td>
								<td width="35%" class="center_note">
									<input type="button" value="Update" onClick="UpdUser()">
								</td>
							</tr>
						</table>
					</form>
					<%
						}
					}
					%>
					<br />
				</div>
			</div>

			<!-- Footer -->
			<%@ include file="/jsp/common/Footer.jsp"%>
			<!-- End Footer -->
		</div>
</body>
</html>